package com.layer8.RPS;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.*;

/**
 * Created with IntelliJ IDEA.
 * User: a873553
 * Date: 1/2/13
 * Time: 10:09 PM
 * To change this template use File | Settings | File Templates.
 */
public class PetChooser extends Activity {

    private Pet pet;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.petchoose);
        final int petID = getIntent().getIntExtra("petID", 0);
        loadPet(petID);
        Button btnSelect = (Button) findViewById(R.id.btnSelect);
        btnSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
                SharedPreferences.Editor editor = prefs.edit();
                editor.putInt("petID", petID);
                editor.commit();
                Intent returnIntent = new Intent();
                returnIntent.putExtra("petID", petID);
                setResult(RESULT_OK, returnIntent);
                finish();
            }
        });
    }

    private void loadPet(int i) {
        PetLoader petLoader;
        petLoader = new PetLoader(this);
        petLoader.loadPetList();
        pet = petLoader.getPet(i);

        ImageView img = (ImageView) findViewById(R.id.petImage);
        TextView name = (TextView) findViewById(R.id.txtName);
        TextView desc = (TextView) findViewById(R.id.txtDesc);
        TextView base = (TextView) findViewById(R.id.txtBase);
        TextView stamina = (TextView) findViewById(R.id.txtStamina);
        TextView physical = (TextView) findViewById(R.id.txtPhys);
        TextView magical = (TextView) findViewById(R.id.txtMag);
        TextView grapple = (TextView) findViewById(R.id.txtGrap);
        TextView skPoint = (TextView) findViewById(R.id.txtSkPoint);
        TextView fMove = (TextView) findViewById(R.id.txtFMove);
        TextView fAtkType = (TextView) findViewById(R.id.txtFAtkType);

        Drawable d = getResources().getDrawable(pet.getImage());
        img.setImageDrawable(d);
        name.setText(pet.getName());
        desc.setText(pet.getDescription());
        base.setText("Base power: " + pet.getBase());
        stamina.setText("Stamina: " + pet.getStamina());
        physical.setText("Physical Strength: " + Double.toString(pet.getStrPhys()));
        magical.setText("Magical Strength: " + Double.toString(pet.getStrMag()));
        grapple.setText("Grapple Strength: " + Double.toString(pet.getStrGrap()));
        skPoint.setText("Skill Point: " + Double.toString(pet.getSkPoint()));
        fMove.setText("Final Move: " + pet.getfMove());
        switch (pet.getfAtkType()) {
            case Physical:
                fAtkType.setText("Final Attack Type: Physical");
                break;
            case Magical:
                fAtkType.setText("Final Attack Type: Magical");
                break;
            case Grapple:
                fAtkType.setText("Final Attack Type: Grapple");
                break;
        }
    }

}
